import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_yn_goods/config/app_color.dart';
import 'package:flutter_yn_goods/config/app_translations.dart';
import 'package:flutter_yn_goods/generated/assets.dart';
import 'package:flutter_yn_goods/widgets/appbar/common_app_bar.dart';
import 'package:flutter_yn_goods/widgets/button/common_button.dart';
import 'package:flutter_yn_goods/widgets/image/auto_image.dart';
import 'package:get/get.dart';
import 'modify_sex_logic.dart';

class ModifySexPage extends StatelessWidget {
  ModifySexPage({Key? key}) : super(key: key);

  final logic = Get.put(ModifySexLogic());
  final state = Get.find<ModifySexLogic>().state;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar:  CommonAppBar(
        title: LocaleKeys.select_gender.tr,
      ),
      body: Padding(
        padding: EdgeInsets.symmetric(horizontal: 16.w),
        child: Column(
          children: [
            16.verticalSpaceFromWidth,
            Obx(() {
              return Row(
                mainAxisSize: MainAxisSize.min,
                children: [
                  InkWell(
                      onTap: () {
                        logic.chooseSex(true);
                      },
                      child: AutoImage(
                        state.isGirl.value == true
                            ? Assets.sexGirlRed
                            : Assets.sexGirlWhite,
                        width: 80.w,
                        height: 80.w,
                      )),
                  60.horizontalSpace,
                  InkWell(
                      onTap: () {
                        logic.chooseSex(false);
                      },
                      child: AutoImage(
                        state.isGirl.value == false
                            ? Assets.sexBoyRed
                            : Assets.sexBoyWhite,
                        width: 80.w,
                        height: 80.w,
                      )),
                ],
              );
            }),
            44.verticalSpaceFromWidth,
            Padding(
                padding: EdgeInsets.symmetric(horizontal: 22.w),
                child: Obx(() {
                  return CommonButton.expend(
                    title: LocaleKeys.save.tr,
                    height: 44.w,
                    enable: logic.state.canChange.value,
                    disableTextColor: AppColor.color86888F,
                    disableBackgroundColor: Colors.black.withOpacity(0.1),
                    onClick: () {
                      if (state.canChange.value) {
                        if (logic.isInit) {
                          Get.back(result: state.isGirl.value == true ? 0 : 1);
                        } else {
                          logic.saveSex();
                        }
                      }
                    },
                  );
                })),
          ],
        ),
      ),
    );
  }
}
